package tests;

/**
 * @author Team TA's
 */

import java.util.ArrayList;
import java.util.HashMap;

import junit.framework.TestCase;
import org.junit.*;

import fi.helsinki.cs.kaisei.*;
import fi.helsinki.cs.kaisei.Weekday.Day;

public class TimetableTest extends TestCase {

	private Timetable timetable;
	private ArrayList<Day> week;
	private ArrayList<Event> events;
	private HashMap<Day, ArrayList<Event>> map;
	
	private int startWeek;
	private int endWeek;
	
	@Before
	public void setUp() throws Exception {
		week = new ArrayList<Day>();
		week.add(Day.MON);
		week.add(Day.TUE);
		week.add(Day.WED);
		week.add(Day.THU);
		week.add(Day.FRI);
		
		events = new ArrayList<Event>();
		events.add(new Event("08", "12", "first", "firstLocation"));
		events.add(new Event("18", "20", "second", "secondLocation"));
		events.add(new Event("12", "14", "third", "thirdLocation"));
		events.add(new Event("10", "16", "fourth", "fourthLocation"));
		events.add(new Event("14", "18", "fifth", "fifthLocation"));
		events.add(new Event("08", "20", "sixth", "sixthLocation"));
		
		map = new HashMap<Day, ArrayList<Event>>();
		for (Day d : week){
			map.put(d, events);
		}
		
		startWeek = 26;
		endWeek = 25;
	}

	@After
	public void tearDown() throws Exception {
		map = null;
		
		events = null;
		
		week = null;		
		
		// if test case forgots to set schedule to null...
		if (timetable != null){
			timetable = null;
		}
	}
	

	@Test
	public void testConstructor() {
		timetable = new Timetable(startWeek,endWeek);
		
		assertNotNull(timetable);
		
		assertEquals(startWeek, timetable.getStartWeek());
		assertEquals(endWeek, timetable.getEndWeek());
		
		assertNotNull(timetable.getSchedule());
		
		timetable = null;
		
		assertNull(timetable);
	}
	
	@Test
	public void testAllSetSchedules() {
		timetable = new Timetable(startWeek,endWeek);

		timetable.setSchedule(map);
		assertEquals(map, timetable.getSchedule());		
	}
	
	@Test
	public void testAddEvent() {
		timetable = new Timetable(startWeek,endWeek);
		Event e = new Event("16", "18", "testAddEvent", "testAddEventLocation");
		timetable.addEvent(Day.FRI, e);
		
		assertEquals(1, timetable.getSchedule().get(Day.FRI).size());
		assertEquals(e, timetable.getSchedule().get(Day.FRI).get(0));
	}
	
}
